package com.java.control.impl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;

import com.java.control.AbstractAdminCommandController;
import com.java.control.search.CodeSearchCond;
import com.java.control.search.SearchStat;
import com.java.entity.Code;
import com.java.service.CodeService;

/**
 * 系统编码管理
 * @author wqf
 * @version  Nov 24, 2011 12:00:53 PM
 */
public class CodeListController extends AbstractAdminCommandController {

	public CodeListController(){
		this.setCommandClass(CodeSearchCond.class);
	}	

	protected ModelAndView executeRequest(HttpServletRequest request,HttpServletResponse response,Object command)
		throws Exception{
		
		CodeSearchCond searchCond = (CodeSearchCond)command;
		
		ModelAndView mav=new ModelAndView(this.view);
		searchCond.setPageSize(10L);
		SearchStat searchStat = this.codeService.getSearchStat(Code.class, searchCond);
		List<Code> list = this.codeService.search(Code.class,searchCond,"codeType,codeSort");
		mav.addObject("searchStat", searchStat);
		mav.addObject("searchCond", searchCond);
		mav.addObject("codeList", list);
		
		List<Code> typelist = this.codeService.searchForSQL(Code.class,"select id,codeType,codeName,codeSort from code group by codeType");
		mav.addObject("codeType", typelist);
		
		return mav;
		
	}
		
	private String view;
	private CodeService codeService;
	
	public void setCodeService(CodeService codeService) {
		this.codeService = codeService;
	}

	public void setView(String view) {
		this.view = view;
	}

}
